<?php defined( 'BASEPATH' ) or die( 'Restricted' ); ?>

<? echo "<?php defined( 'BASEPATH' ) or die( 'Restricted' );"; ?>

/*
-----------------------------------------------------------------------------
| This file is copyright 2011 by ALL RIGHTS RESERVED.
|----------------------------------------------------------------------------
| Form: <?= $ds->form; ?>

Regenerate URL:
<?= URL( $page )->setVar( 'h', base64_encode( serialize( $ds->dataArray() ) ) ) . "\n\n"; ?>
|----------------------------------------------------------------------------
| Date			| Person		| Change Description
|----------------------------------------------------------------------------
| <?= date::currentDate(); ?>	| <?= $ds->developer; ?>	| Created
-----------------------------------------------------------------------------
*/

class <?= $ds->formClassName; ?> extends tgsfForm
{
	protected function _setup()
	{
		$this->id( '<?= $ds->formId; ?>' );
		$this->useTemplate( '<?= $ds->template; ?>'<?= $ds->exists( 'inapp' )?', IS_APP':''; ?> );
		
<?php
		$fieldInfo = $ds->fields;
		
		$lines = explode( "\n", $fieldInfo );
		
		foreach( $lines as $line )
		{
			$line = trim($line);
			if ( strpos( $line, '|' ) === false )
			{
				// this is a group
				echo "\t\t" . '$this->startGroup( \'' . $line . '\' );' . PHP_EOL;
			}
			else
			{
				list( $name, $type, $caption ) = explode( '|', $line );
				echo "\t\t" . '$this->_( ' . $type . ' )->caption( \'' . $caption . '\' )->name( \'' . $name . '\' );' . PHP_EOL;
				$fields[] = (object) array( 'caption' => $caption, 'name' => $name, 'type' => $type );
			}
		}
		
		?>

		//------------------------------------------------------------------------
		// BUTTONS
		//------------------------------------------------------------------------

		$this->startGroup( '_buttons' );
		$this->_( fftSubmit )->caption( 'Save' )->name( 'go' )->setFieldAttribute( 'class', 'ui-priority-primary' );

		$this->_( fftButton )
		     ->caption( 'Cancel' )
		     ->name( 'cancel' )
		     ->setFieldAttribute( 'type', 'button' )
		     ->setFieldAttribute( 'onclick', "return tgsf.URL( '<?= $ds->cancel_url; ?>' ).redirect()" );
	}

	//------------------------------------------------------------------------

	protected function _setupValidate( &$v )
	{
<?
		foreach( $fields as $field )
		{
			echo "\t\t" . '$v->_( \'' . $field->name . '\' )->required();' . PHP_EOL;
		}
		?>
	}

	//------------------------------------------------------------------------
}

return new <?= $ds->formClassName; ?>();